package com.shopsmart.android.utils;

import java.util.ArrayList;
import java.util.Collections;

import android.util.DisplayMetrics;

public class MagneticPointsUtility {
	
	

    /**
     * Method to sort all the Magnetic X Axis & Y axis points.
     * It returns the list of extreme co-ordinates in the following order:
     * xMax, yMax, xMin & yMin
     * @param xMagPoints
     * @param yMagPoints
     */
    public ArrayList<Float> getExteremeDataPoints(ArrayList<Float> xMagPoints, ArrayList<Float> yMagPoints){
        Float xMax = Collections.max(xMagPoints);
        Float yMax = Collections.max(yMagPoints);
        Float xMin = Collections.min(xMagPoints);
        Float yMin = Collections.min(yMagPoints);
        ArrayList<Float> extermePointsList = new ArrayList<Float>();
        extermePointsList.add(xMax);
        extermePointsList.add(yMax);
        extermePointsList.add(xMin);
        extermePointsList.add(yMin);
        return extermePointsList;
    }

    
    /**
     * Method to transform the actual magnetic x and y axis values to values relative to device resolution.
     * It returns the list of relative co-ordinates for x and y axis resp.
     * 
     * @param actualMagPointsList
     * @param extermePointsList
     */
    public ArrayList<Float> getRelativePosition(ArrayList<Float> actualMagPointsList,  ArrayList<Float> extermePointsList){
        DisplayMetrics displaymetrics = new DisplayMetrics();
        //TODO get WindowsManager
        Integer deviceYRange = (Integer)displaymetrics.heightPixels;
        Integer deviceXRange = (Integer)displaymetrics.widthPixels;
        
        
        Float relativeXMagPoint = (deviceXRange/(extermePointsList.get(0) - extermePointsList.get(2))) * actualMagPointsList.get(0);
        Float relativeYMagPoint = (deviceYRange/(extermePointsList.get(1) - extermePointsList.get(3))) * actualMagPointsList.get(1);
        ArrayList<Float> relativePointsList = new ArrayList<Float>();
        relativePointsList.add(relativeXMagPoint);
        relativePointsList.add(relativeYMagPoint);
        
        return relativePointsList;
    }

}
